package remote;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;


import server.SimpleDB;
import storage.transaction.Transaction;

class RemoteConnectionImpl extends UnicastRemoteObject implements
RemoteConnection {


	private static final long serialVersionUID = -2675186360394557804L;
	
	private Transaction tx;
	private boolean auto = true;
	
	RemoteConnectionImpl() throws RemoteException {
		tx = new Transaction();
	}
	
	public RemoteStatement createStatement() throws RemoteException {
		return new RemoteStatementImpl(this, auto);
	}

	public void close() throws RemoteException {
		tx.commit();
	}
	
	Transaction getTransaction() {
		return tx;
	}
	
	public void commit() {
		tx.commit();
		tx = new Transaction();
	}
	
	public void rollback() {
		tx.rollback();
		tx = new Transaction();
	}
	
	public void setAutoCommit(boolean autoCommit) throws RemoteException {
		auto = autoCommit;
	}
}
